<!DOCTYPE html>
<html>
<head>
    <title>日志列表</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 指定以IE8的方式来渲染 -->
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>
    <link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="/css/jsherp.css"/>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/icon.css"/>
    <link type="text/css" rel="stylesheet" href="/css/common.css"/>
    <script type="text/javascript" src="/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common/common.js"></script>
</head>
<body>
<!-- 数据显示table -->
<div id="tablePanel" class="easyui-panel" data-options="fit:true" style="padding:1px;top:300px;" title="操作日志列表" iconCls="icon-list">
    <div class="box-body form-inline">
        <div class="form-group">
            <label class="control-label">操作模块：</label>
            <div class="control-inline">
                <input type="text" id="searchOperation" name="searchOperation" value="" maxlength="100" class="easyui-textbox width-90"/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">操作人员：</label>
            <div class="control-inline">
                <select name="searchUsernameID" id="searchUsernameID" class="width-90"
                        style="height: 30px;border: 1px solid #95B8E7;border-radius:5px;"></select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">操作IP：</label>
            <div class="control-inline">
                <input type="text" id="searchIP" name="searchIP" value="" maxlength="100" class="easyui-textbox width-90"/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">操作状态：</label>
            <div class="control-inline">
                <select name="searchStatus" id="searchStatus" class="easyui-combobox"
                        data-options="panelHeight:'auto'" style="width:90px;">
                    <option value="">全部</option>
                    <option value="0">成功</option>
                    <option value="1">失败</option>
                </select>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="form-group">
            <label class="control-label">操作详情：</label>
            <div class="control-inline">
                <input type="text" id="searchDesc" name="searchDesc" value="" maxlength="100" class="easyui-textbox width-90"/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">开始时间：</label>
            <div class="control-inline">
                <input type="text" id="searchBeginTime" name="searchBeginTime" class="easyui-datetimebox width-140"/>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">结束时间：</label>
            <div class="control-inline">
                <input type="text" id="searchEndTime" name="searchEndTime" class="easyui-datetimebox width-140"/>
            </div>
        </div>
        <div class="form-group">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" id="searchBtn">查询</a>&nbsp;
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-redo" id="searchResetBtn">重置</a>
        </div>
    </div>
    <table id="tableData" style="height:340px;top:300px;border-bottom-color:#FFFFFF"></table>
</div>
<script type="text/javascript">
    var userList = null;
    //初始化界面
    $(function () {
        initTableData();
        ininPager();
        //初始化系统基础信息
        initSystemData();
        //初始化页面系统基础信息选项卡
        initSelectInfo();
    });

    //初始化表格数据
    function initTableData() {
        $('#tableData').datagrid({
            //title:'供应商列表',
            //iconCls:'icon-save',
            //width:700,
            height: heightInfo,
            nowrap: false,
            rownumbers: true,
            //动画效果
            animate: false,
            //选中单行
            singleSelect: true,
            collapsible: false,
            selectOnCheck: false,
            //fitColumns:true,
            //单击行是否选中
            checkOnSelect: false,
            //交替出现背景
            striped: true,
            pagination: true,
            //loadFilter: pagerFilter,
            pageSize: initPageSize,
            pageList: initPageNum,
            columns: [[
                {title: '操作模块', field: 'operation', width: 120},
                {title: '操作详情', field: 'contentdetails', width: 350},
                {title: '操作人员', field: 'username', width: 100, align: "center"},
                {title: '操作状态',field: 'status',width:80,align:"center",formatter:function(value){
                    return value? "失败":"成功";
                }},
                {title: '操作IP', field: 'clientip', width: 100, align: "center"},
                {title: '操作时间', field: 'createTimeStr', width: 150, align: "center"}
            ]],
            onLoadError: function () {
                $.messager.alert('页面加载提示', '页面加载异常，请稍后再试！', 'error');
                return;
            }
        });
        dgResize();
        showLogDetails(1, initPageSize);
    }

    //初始化键盘enter事件
    $(document).keydown(function (event) {
        //兼容 IE和firefox 事件
        var e = window.event || event;
        var k = e.keyCode || e.which || e.charCode;
        //兼容 IE,firefox 兼容
        var obj = e.srcElement ? e.srcElement : e.target;
        //绑定键盘事件为 id是指定的输入框才可以触发键盘事件 13键盘事件
        //搜索按钮添加快捷键
        if (k == "13" && (obj.id == "searchOperation" || obj.id == "searchUsernameID" || obj.id == "searchIP"
                || obj.id == "searchStatus" || obj.id == "searchBeginTime" || obj.id == "searchEndTime"
                || obj.id == "searchDesc")) {
            $("#searchBtn").click();
        }
    });

    //分页信息处理
    function ininPager() {
        try {
            var opts = $("#tableData").datagrid('options');
            var pager = $("#tableData").datagrid('getPager');
            pager.pagination({
                onSelectPage: function (pageNum, pageSize) {
                    opts.pageNumber = pageNum;
                    opts.pageSize = pageSize;
                    pager.pagination('refresh',
                        {
                            pageNumber: pageNum,
                            pageSize: pageSize
                        });
                    showLogDetails(pageNum, pageSize);
                }
            });
        }
        catch (e) {
            $.messager.alert('异常处理提示', "分页信息异常 :  " + e.name + ": " + e.message, 'error');
        }
    }


    //初始化系统基础信息
    function initSystemData() {
        $.ajax({
            type: "get",
            url: "/user/getAllList",
            //设置为同步
            async: false,
            dataType: "json",
            success: function (res) {
                //成功关闭loading
                if(res && res.code === 200){
                    userList = res.data.userList;
                }
            }
        });
    }

    //初始化页面选项卡
    function initSelectInfo() {
        var options = "";
        if (userList != null) {
            options = "";
            for (var i = 0; i < userList.length; i++) {
                var user = userList[i];
                if (0 == i) {
                    userID = user.id
                }
                options += '<option value="' + user.id + '">' + user.username + '</option>';
            }
            $("#searchUsernameID").empty().append('<option value="">请选择</option>').append(options);
        }
    }

    //搜索处理
    $("#searchBtn").unbind().bind({
        click: function () {
            showLogDetails(1, initPageSize);
            var opts = $("#tableData").datagrid('options');
            var pager = $("#tableData").datagrid('getPager');
            opts.pageNumber = 1;
            opts.pageSize = initPageSize;
            pager.pagination('refresh',
                {
                    pageNumber: 1,
                    pageSize: initPageSize
                });
        }
    });

    function showLogDetails(pageNo, pageSize) {
        var operation = $.trim($("#searchOperation").val());
        var usernameID = $.trim($("#searchUsernameID").val());
        var clientIp = $.trim($("#searchIP").val());
        var status = $.trim($("#searchStatus").val());
        var beginTime = $.trim($("#searchBeginTime").datebox("getValue"));
        var endTime = $.trim($("#searchEndTime").datebox("getValue"));
        var contentdetails = $.trim($("#searchDesc").val());
        $.ajax({
            type: "get",
            url: "/log/list",
            dataType: "json",
            data: ({
                search: JSON.stringify({
                operation: operation,
                usernameID: usernameID,
                clientIp: clientIp,
                status: status,
                beginTime: beginTime,
                endTime: endTime,
                contentdetails: contentdetails
                }),
                currentPage: pageNo,
                pageSize: pageSize
            }),
            success: function (res) {
                if(res && res.code === 200){
                    if(res.data && res.data.page) {
                        $("#tableData").datagrid('loadData', res.data.page);
                    }
                }
            },
            //此处添加错误处理
            error: function () {
                $.messager.alert('查询提示', '查询数据后台异常，请稍后再试！', 'error');
                return;
            }
        });
    }

    //重置按钮
    $("#searchResetBtn").unbind().bind({
        click: function () {
            $("#searchOperation").textbox("clear");
            $("#searchUsernameID").val("");
            $("#searchIP").textbox("clear");
            $("#searchStatus").textbox("setValue","");
            $("#searchBeginTime").datebox("clear");
            $("#searchEndTime").datebox("clear");
            $("#searchDesc").textbox("clear");
            //加载完以后重新初始化
            $("#searchBtn").click();
        }
    });
</script>
</body>
</html>